// 防抖,当用户操作较为频繁时,只发送最后一次结果作为请求
// 在这里我用的时ts写的,对于传入的值有严格的效验
let Trembling = (fn: Function, deplay: number) => {
    let timer: any = null
    return () => {
        if (timer !== null) { clearTimeout(timer) }
        timer = setTimeout(() => { fn() }, deplay);
    }
}
// 节流,控制用户在特定的事件的内发送请求，减少用户发送请求的频次
let throttle = (fn: Function, deplay: number) => {
    let flag = true
    return () => {
        flag && setTimeout(() => { fn(), flag = true }, deplay)
        flag = false
    }
}
export {
    Trembling,
    throttle
}